package com.fingard.dsp.bank.reqrespobj.transaction;

import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.specialDeal.BankAreaHelper;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RequestBase;
import com.fingard.xml.XmlTextReader;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;

public class Req7516HisTrans extends RequestBase {

    /*
<ActArea></ActArea>
            <ActCur></ActCur>
            <ActNum></ActNum>
            <IsNonStandard></IsNonStandard>
            <DateFrom></DateFrom>
            <DateTo></DateTo>
     * */
    //账号ID（民生银行全球现金池使用）alon Created 2019-12-06
    public String accountId = "";

    public String actArea = "";
    public String actCur = "";
    public String actNum = "";
    public String dateFrom = "";
    public String dateTo = "";
    public String isSpecialAct = "";
    //上级账户
    public String higherLevelAct;

    /*账户机构类型
    中信银行附属账户：2
    农行多级账簿：3
    工行全球现金池：4
    工行账户管家：5
    中信银行附属虚拟账户：6
    */
    public String actBankType = "";
    //上一笔柜员号
    public String tranNo;

    public String isReqFromDsp = "";

    //外资银行新增字段
    //银行类型
    public String bankType;
    //付款方IBAN
    public String payIBAN;
    public String timeZone;
    //账户所在行的swiftcode
    public String swiftCode;
    //账户类型 1-活期2-定期3-保证金
    public String savingType;
    //是否虚拟户
    public boolean isVirtual;
    //虚拟户编号
    public String virtualNo;
    //直联账户权限
    public HashSet<String> directRight;


    private XmlTextReader xmlReader;

    public Req7516HisTrans(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception {
        reqHeader = p_header;
        xmlReader = p_xmlReader;
        actArea = xmlReader.getSimpleText("ActArea");
        if (FGBiz.dspCenter.convertBankArea) {
            BankAreaHelper bankAreaHelper = new BankAreaHelper(p_header.bankCode, actArea, "");
            bankAreaHelper.toBank();
            actArea = bankAreaHelper.bankAreaCode;
        }
        accountId = xmlReader.getSimpleText("AccountId");
        actCur = xmlReader.getSimpleText("ActCur");
        actNum = xmlReader.getSimpleText("ActNum");
        dateFrom = xmlReader.getSimpleText("DateFrom");
        dateTo = xmlReader.getSimpleText("DateTo");
        isSpecialAct = xmlReader.getSimpleTextNotNull("IsSpecialAct");
        higherLevelAct = xmlReader.getSimpleTextNotNull("HigherLevelAct");
        actBankType = xmlReader.getSimpleTextNotNull("ActBankType");
        tranNo = xmlReader.getSimpleTextNotNull("TranNo");
        isReqFromDsp = xmlReader.getSimpleTextNotNull("IsReqFromDsp");
        bankType = xmlReader.getSimpleTextNotNull("BankType");
        payIBAN = xmlReader.getSimpleTextNotNull("PayIBAN");
        timeZone = xmlReader.getSimpleTextNotNull("TimeZone");
        swiftCode = xmlReader.getSimpleText("swiftcode");
        savingType = xmlReader.getSimpleText("SavingType");
        if ("1".equals(xmlReader.getSimpleText("IsVirtual"))) {
            isVirtual = true;
        } else {
            isVirtual = false;
        }
        virtualNo = xmlReader.getSimpleText("VirtualNo");
        String[] directRights = xmlReader.getSimpleTextNotNull("DirectRight").split(",");
        directRight = new HashSet<String>(Arrays.asList(directRights));
    }

    public Req7516HisTrans(ReqRespHeader p_header) {
        reqHeader = p_header;
    }

    public Date getDateFrom() throws ParseException {
        return Format.Date8Format.parse(dateFrom);
    }

    public Date getDateTo() throws ParseException {
        return Format.Date8Format.parse(dateTo);
    }

    public String getOriReqXml() {
        return xmlReader.getOriXmlString();
    }
}
